package dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import pojo.TblManager;
import pojo.TblRegisterUser;

import comment.HibernateSessionFactory;

public class TblManagerDao {
	Transaction tc = null;
	public void addTblManager(TblRegisterUser tblRegisterUser){
		try{
			Session session = HibernateSessionFactory.getSession();
			tc = session.beginTransaction();
			session.save(tblRegisterUser);
			tc.commit();
		}catch(Exception e){
			e.printStackTrace();
			if(tc!=null){
				tc.rollback();
			}
		}
		finally{
			HibernateSessionFactory.closeSession();
		}
	}
	
	public TblManager findTblManager(int id){
		TblManager tblManager = new TblManager();
		try{
			Session session = HibernateSessionFactory.getSession();
			tblManager = (TblManager) session.get(TblManager.class, id);
		}finally{
			HibernateSessionFactory.closeSession();
		}
		return tblManager;
	}
	
	public List<TblManager> findTblManagerList(String hql){
		List<TblManager> tblManagerListList = null;
		Session session = null;
		try{
			session  = HibernateSessionFactory.getSession();
			Query hqlQuery = session.createQuery(hql);
			tblManagerListList = hqlQuery.list();
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			HibernateSessionFactory.closeSession();
		}
		return tblManagerListList;
	}

}
